package com.bootdo.imook.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.ResultAjax;
import com.bootdo.imook.domain.QuesTitleNewDO;
import com.bootdo.imook.service.QuesTitleNewService;

/**
 * 慕课网手记-推荐文章
 *
 * @author hylu
 * @email 1325101787@qq.com
 * @date 2017-11-10 15:03:47
 */
@Controller
@RequestMapping("/imook/quesTitleNew")
public class QuesTitleNewController {
    @Autowired
    private QuesTitleNewService quesTitleNewService;

    @GetMapping()
    @RequiresPermissions("imook:quesTitleNew:quesTitleNew")
    String QuesTitleNew() {
        return "imook/quesTitleNew/quesTitleNew";
    }

    @GetMapping("/add")
    @RequiresPermissions("imook:quesTitleNew:add")
    String add() {
        return "imook/quesTitleNew/add";
    }

    @GetMapping("/edit/{id}")
    /*@RequiresPermissions("imook:quesTitleNew:edit")*/
    String edit(@PathVariable("id") Long id, Model model) {
        QuesTitleNewDO quesTitleNew = quesTitleNewService.get(id);

        model.addAttribute("quesTitleNew", quesTitleNew);

        return "imook/quesTitleNew/edit";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("imook:quesTitleNew:quesTitleNew")
    public PageUtils list(@RequestParam Map<String, Object> params) {

        // 查询列表数据
        Query                query            = new Query(params);
        List<QuesTitleNewDO> quesTitleNewList = quesTitleNewService.list(query);
        int                  total            = quesTitleNewService.count(query);
        PageUtils            pageUtils        = new PageUtils(quesTitleNewList, total);

        return pageUtils;
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("imook:quesTitleNew:remove")
    public ResultAjax remove(Long id) {
        if (quesTitleNewService.remove(id) > 0) {
            return ResultAjax.ok();
        }

        return ResultAjax.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("imook:quesTitleNew:batchRemove")
    public ResultAjax remove(@RequestParam("ids[]") Long[] ids) {
        quesTitleNewService.batchRemove(ids);

        return ResultAjax.ok();
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("imook:quesTitleNew:add")
    public ResultAjax save(QuesTitleNewDO quesTitleNew) {
        if (quesTitleNewService.save(quesTitleNew) > 0) {
            return ResultAjax.ok();
        }

        return ResultAjax.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("imook:quesTitleNew:edit")
    public ResultAjax update(QuesTitleNewDO quesTitleNew) {
        quesTitleNewService.update(quesTitleNew);

        return ResultAjax.ok();
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
